package com.sun.demo;

import com.sun.demo.job.Job01;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

/**
 * CronScheduleBuilder 使用cron表达式执行定时任务
 */
public class QuartzTest03 {
    public static void main(String[] args) {
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

            scheduler.start();

            JobDetail jobDetail = JobBuilder.newJob(Job01.class).build();

            CronTrigger trigger = TriggerBuilder.newTrigger()
                    .startNow()
                    .withSchedule(
                            CronScheduleBuilder.cronSchedule("* * * * * ? *")
                    ).build();

            scheduler.scheduleJob(jobDetail,trigger);
            TimeUnit.SECONDS.sleep(3);
            scheduler.shutdown();

        } catch (SchedulerException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
